package my219;

import java.util.HashMap;
import java.util.Map;

public class SuanFa219 {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer,Integer> map= new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(nums[i]) && Math.abs(i- map.get(nums[i])) <=k){
                return true;
            }
            map.put(nums[i],i);

            }
        return false;

    }
    public static void main(String[] args) {
        SuanFa219 suanFa219 = new SuanFa219();
        int[] nums = {1,3,4,1,2};
        boolean b = suanFa219.containsNearbyDuplicate(nums, 3);
        System.out.println(b);

    }
}
